// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import animated from 'animate.css' 
import lazyload from "vue-lazyload" 
import lodash from 'lodash'
import './assets/scss/style.scss'
import moment from 'moment' // 导入文件
import 'moment/locale/zh-cn'
import './assets/css/animate.css'
import './components'              
moment.locale('zh-cn');
import Vconsole from 'vconsole';  //移动端调试工具
// if(process.env.NODE_ENV == 'development') { // 打包后隐藏
  const  vConsole =  new Vconsole();
  Vue.use(vConsole);
// }
Vue.use(animated)
Vue.use(lodash)
Vue.use(moment)

Vue.use(lazyload, {
	preLoad: 1.3,
	error: require('./assets/img/no-img.png'),
	loading: require('./assets/img/no-img.png'),
	attempt: 1
})

Vue.config.productionTip = false

const whiteList = ['/login'];// 不重定向白名单
router.beforeEach((to, from, next) => {
	if (to.meta.title) {
		document.title = to.meta.title;
	}
	if(localStorage.getItem('TokenKey')){
		next()
	}else{
		if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单，直接进入
			next()
		} else {
			next('/login'); // 否则全部重定向到登录页
			// next()
		}
	}
});

/* eslint-disable no-new */
new Vue({
	data(){
		return{
			userId: localStorage.getItem("userId")
		}
	},
	el: '#app',
	router,
	store,
	components: { App },
	template: '<App/>'
})

